﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.SqlServer.Management.Smo;
using Chi.Lib.DBHelper;
using System.Diagnostics;

public partial class ShowCommandSMO : System.Web.UI.Page
{
    Database db;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            db = DBHelperSMO.GetDBInstance();
            if (Request.QueryString["spName"] != null)
            {
                this.ux_spName.Text = Request.QueryString["spName"];
            }

            GetSPInfo(Request.QueryString["spName"]);
        }


    }

    public string GetSPInfo(string spName)
    {
        if (string.IsNullOrEmpty(spName) & 
            !db.StoredProcedures.Contains(spName))
            return null;
        StoredProcedure sp = db.StoredProcedures[spName];
        ux_LastModifyDate.Text = sp.DateLastModified.ToLongDateString();
        ux_Text.Text = sp.Properties["Text"].Value.ToString();

        for (int i = 0; i < sp.Properties.Count; i++)
        {
            Debug.WriteLine(sp.Properties[i].Name + "________" +
                sp.Properties[i].Value);
        }

        return "";
    }
}
